package com.drakulo.hi.gfx;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class Gauge implements HIGraphicComponent {
	private static int BAR_PADDING = 5;

	private int originX;
	private int originY;
	private int width;
	private Color color;
	private int percent;
	private int maxValue;
	private int currentValue;

	public Gauge(Color color) {
		this.color = color;
	}

	public Gauge(int p_originX, int p_originY, int p_width, Color p_color, int p_percent) {
		this.originX = p_originX;
		this.originY = p_originY;
		this.width = p_width;
		this.color = p_color;
		this.percent = p_percent;
		this.maxValue = -1;
		this.currentValue = -1;
	}

	public Gauge(int p_originX, int p_originY, int p_width, Color p_color, int p_maxValue,
			int p_currentValue) {
		this.originX = p_originX;
		this.originY = p_originY;
		this.width = p_width;
		this.color = p_color;
		this.percent = -1;
		this.maxValue = p_maxValue;
		this.currentValue = p_currentValue;
	}

	public Color getColor() {
		return this.color;
	}

	public int getCurrentValue() {
		return this.currentValue;
	}

	public int getMaxValue() {
		return this.maxValue;
	}

	public int getOriginX() {
		return this.originX;
	}

	public int getOriginY() {
		return this.originY;
	}

	public int getWidth() {
		return this.width;
	}

	@Override
	public boolean mouseIsOnIt(int mouseX, int mouseY) {
		return false;
	}

	@Override
	public void render(Graphics g) throws SlickException {
		render(g, this.originX, this.originY);
	}

	@Override
	public void render(Graphics g, int x, int y) throws SlickException {
		int paddingTop = 15;
		g.setColor(Color.black);
		g.fillRect(x + BAR_PADDING, y + paddingTop, this.width - 2 * BAR_PADDING, 10);

		g.setColor(this.color);

		boolean displayValues = false;
		if (this.maxValue > 0 && this.currentValue > 0) {
			this.percent = this.currentValue * 100 / this.maxValue;
			displayValues = true;
		}
		int w = (this.width - 2 * BAR_PADDING) * this.percent / 100;

		g.fillRect(x + BAR_PADDING, y + paddingTop, w, 10);
		if (displayValues) {
			String values = String.valueOf(this.currentValue) + " / "
					+ String.valueOf(this.maxValue);
			FontFactory.getGaugeFont().drawString(x + 10 + BAR_PADDING, y + 1, values, Color.white);
		}
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public void setCurrentValue(int currentValue) {
		this.currentValue = currentValue;
	}

	public void setMaxValue(int maxValue) {
		this.maxValue = maxValue;
	}

	public void setOriginX(int originX) {
		this.originX = originX;
	}

	public void setOriginY(int originY) {
		this.originY = originY;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	@Override
	public void update(Input input) {
	}
}
